function formatDate(num, showTime) {
	var now = new Date();
	var nowTime = now.getTime();
	var oneDayTime = 24 * 60 * 60 * 1000;
	var ShowTime = nowTime + num * oneDayTime;
	var myDate = new Date(ShowTime);
	var y = myDate.getFullYear(); //年
	var m = myDate.getMonth() + 1; //月
	var d = myDate.getDate(); //日
	var hour = myDate.getHours(); //时
	var minute = myDate.getMinutes(); //分
	var second = myDate.getSeconds(); //秒
	if (showTime) {
		return [y, m, d].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':');
	} else {
		return [y, m, d].map(formatNumber).join('-');
	}
}
const formatNumber = (n) => {
	n = n.toString();
	return n[1] ? n : '0' + n;
};
/**
 * GET请求封装
 */
function get(url, data = {}) {
	return request(url, data, 'GET');
}
/**
 * POST请求封装
 */
function post(url, data = {}) {
	return request(url, data, 'POST');
}
/**
 * 微信的request
 */
function request(url, data = {}, method = 'GET') {
	return new Promise(function(resolve, reject) {

		const token = uni.getStorageSync('token')
		uni.request({
			url: url,
			data: data,
			method: method,
			header: {
				'Content-Type': 'application/json',
				'Authorization': "Bearer " + uni.getStorageSync('token')
			},
			success: function(res) {
				console.log(
					'==============================================================================================='
				);
				console.log('==    接口地址：' + url);
				// console.log('==    token：' + uni.getStorageSync('token'));
				console.log('==    接口参数：' + JSON.stringify(data));
				// console.log('==    请求类型：' + method);
				console.log('==    返回数据： ==');
				console.log(res.data);
				console.log(
					'==============================================================================================='
				);
				var result = res.data

				if (token && (result.code == 403 || result.code ==
						401)) {
					uni.showToast({
						title: "身份过期重新登入",
						icon: "none"
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/index/index'
						});
					}, 1000)
				} else {
					resolve(res.data);
				}
				uni.hideLoading();
			},
			fail: function(err) {
				//服务器连接异常
				console.log(
					'==============================================================================================='
				);
				console.log('==    接口地址：' + url);
				console.log('==    接口参数：' + JSON.stringify(data));
				console.log('==    请求类型：' + method);
				console.log('==    服务器连接异常');
				console.log(
					'==============================================================================================='
				);
				reject('服务器连接异常，请检查网络再试');
			}
		});
	});
}
module.exports = {
	formatDate,
	request,
	get,
	post
};